package com.jack.cms.oss.core;
//package com.calm.talent.core.common.file.core;
//
//
//import org.codehaus.jackson.*;
//import org.codehaus.jackson.map.*;
//import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
//import org.codehaus.jackson.map.ser.CustomSerializerFactory;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import java.io.IOException;
//import java.io.StringWriter;
//import java.io.Writer;
//import java.text.SimpleDateFormat;
//import java.util.Date;
//import java.util.HashMap;
//
//public class JsonUtil {
//    private static Logger logger = LoggerFactory.getLogger(JsonUtil.class);
//
//    public static String toJsonString(Object object) {
//        return toJson(object);
//    }
//
//    public static String toJsonString(Object... object) {
//        return toJson(object);
//    }
//
//    public static String beanToJsonNotNull(Object object) {
//        StringWriter out = new StringWriter();
//        try {
//            ObjectMapper mapper = new MyObjectMapper();
//            mapper.setSerializationInclusion(Inclusion.NON_NULL);
//            JsonGenerator creator = mapper.getJsonFactory().createJsonGenerator(out);
//            creator.writeObject(object);
//        } catch (Exception e) {
//            out.write(object == null ? "null" : object.toString());
//        }
//        return out.toString();
//    }
//
//    private static String toJson(Object object) {
//        StringWriter out = new StringWriter();
//        try {
//            ObjectMapper mapper = new MyObjectMapper();
//            // mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES,
//            // false);
//            JsonGenerator creator = mapper.getJsonFactory().createJsonGenerator(out);
//            creator.writeObject(object);
//        } catch (Exception e) {
//            out.write(object == null ? "null" : object.toString());
//        }
//        return out.toString();
//    }
//
//
//    public static class MyObjectMapper extends ObjectMapper {
//        public MyObjectMapper() {
//            CustomSerializerFactory factory = new CustomSerializerFactory();
//            this.addDateGenericMapping(factory);
//            this.addEnumGenericMapping(factory);
//            this.setSerializerFactory(factory);
//        }
//
//        @SuppressWarnings("rawtypes")
//        private void addEnumGenericMapping(CustomSerializerFactory factory) {
//            factory.addGenericMapping(Enum.class, new JsonSerializer<Enum>() {
//                @Override
//                public void serialize(Enum value, JsonGenerator jsonGenerator,
//                    SerializerProvider provider) throws IOException, JsonProcessingException {
//                    if (value instanceof BaseEnum) {
//                        Integer backValue = ((BaseEnum) value).getBackValue();
//                        jsonGenerator.writeString(String.valueOf(backValue));
//                    }
//                }
//            });
//        }
//
//        private void addDateGenericMapping(CustomSerializerFactory factory) {
//            factory.addGenericMapping(Date.class, new JsonSerializer<Date>() {
//                @Override
//                public void serialize(Date value, JsonGenerator jsonGenerator,
//                    SerializerProvider provider) throws IOException, JsonProcessingException {
//                    String dateString = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(value);
//                    if (dateString.endsWith(" 00:00:00")) {
//                        dateString = new SimpleDateFormat("yyyy-MM-dd").format(value);
//                    } else if (dateString.startsWith("1970-01-01")) {
//                        dateString = new SimpleDateFormat("HH:mm:ss").format(value);
//                    }
//                    jsonGenerator.writeString(dateString);
//                }
//            });
//        }
//
//    }
//
//    /**
//     * json转化为javabean对象
//     *
//     * @param json
//     * @param cls
//     * @return
//     */
//    public static Object json2Object(String json, Class<?> cls) {
//        Object obj = null;
//        ObjectMapper mapper = new ObjectMapper();
//        SimpleDateFormat formatter = DateUtil.getDateFormat(true);
//        mapper.setDateFormat(formatter);
//        mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//        mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
//        try {
//
//            obj = mapper.readValue(json, cls);
//        } catch (JsonParseException e) {
//            logger.error("", e);
//        } catch (JsonMappingException e) {
//            // TODO Auto-generated catch block
//            logger.error("", e);
//        } catch (IOException e) {
//            // TODO Auto-generated catch block
//            logger.error("", e);
//        }
//
//        return obj;
//    }
//
//    /**
//     * javabean对象转化为json
//     *
//     * @param obj
//     * @return
//     */
//    public static String object2Json(Object obj) {
//        ObjectMapper mapper = new ObjectMapper();
//        Writer writer = new StringWriter();
//        SimpleDateFormat formatter = DateUtil.getDateFormat(true);
//        mapper.setDateFormat(formatter);
//        String json = null;
//
//        try {
//            mapper.writeValue(writer, obj);
//            json = writer.toString();
//        } catch (JsonGenerationException e) {
//            // TODO Auto-generated catch block
//            logger.error("", e);
//        } catch (JsonMappingException e) {
//            // TODO Auto-generated catch block
//            logger.error("", e);
//        } catch (IOException e) {
//            // TODO Auto-generated catch block
//            logger.error("", e);
//        } finally {
//            try {
//                writer.close();
//            } catch (IOException e) {
//                // TODO Auto-generated catch block
//                logger.error("", e);
//            }
//        }
//
//        return json;
//
//    }
//
//    // public static void main(String[] args) {
//    // SpecialMarketingVo marketVo = new SpecialMarketingVo();
//    // marketVo.setId(125);
//    // marketVo.setBrandId(2192l);
//    // marketVo.setIsShare(YesNoEnum.YES);
//    // marketVo.setPlanDesc("你好");
//    // marketVo.setPlanEndDay(new Date());
//    //
//    // SpecialMarketingCouponVo couponVo = new SpecialMarketingCouponVo();
//    // MarketCouponRule couponRule = new MarketCouponRule();
//    // couponRule.setRedirectType(RedirectTypeEnum.COPY);
//    // couponRule.setStartTime("2014-12-16 19:56:01");
//    // couponVo.setCouponRule(couponRule);
//    //
//    // MarketAssCoupon marketAssCoupon = new MarketAssCoupon();
//    // marketAssCoupon.setCouponId(568);
//    // marketAssCoupon.setUpdateTime(new Date());
//    // couponVo.setMarketAssCoupon(marketAssCoupon);
//    //
//    // MarketCustomerGroup customerGroup = new MarketCustomerGroup();
//    // customerGroup.setIsBookingShop(YesNoEnum.NO);
//    // customerGroup.setBookingFrequency(3);
//    // couponVo.setCustomerGroup(customerGroup);
//    //
//    // MarketPlanPublishVo planPublish = new MarketPlanPublishVo();
//    // planPublish.setSysFileId(32l);
//    // planPublish.setCommercialId("800000001");
//    // couponVo.setPlanPublish(planPublish);
//    //
//    // List<MarketSendDayRule> sendDayRuleList = new ArrayList<MarketSendDayRule>();
//    // MarketSendDayRule sendDayRule = new MarketSendDayRule();
//    // sendDayRule.setPlanId(125);
//    // sendDayRule.setTimeType(TimeTypeEnum.FESTIVAL);
//    // sendDayRuleList.add(sendDayRule);
//    // couponVo.setSendDayRuleList(sendDayRuleList);
//    //
//    // List<MarketDynamicCondition> dynamicConditionList = new ArrayList<MarketDynamicCondition>();
//    // MarketDynamicCondition dynamicCondition = new MarketDynamicCondition();
//    // dynamicCondition.setPlanId(125);
//    // dynamicCondition.setId(1);
//    // dynamicCondition.setConditionValue(5);
//    // dynamicConditionList.add(dynamicCondition);
//    // couponVo.setDynamicConditionList(dynamicConditionList);
//    //
//    // marketVo.setCoupon(couponVo);
//    //
//    // String json = object2Json(marketVo);
//    // System.out.println(json);
//    //
//    // String sourceStr =
//    // "{\"creatorId\":null,\"updaterId\":null,\"createTime\":null,\"updateTime\":null,\"isDelete\":null,\"updaterName\":null,\"creatorName\":null,\"id\":125,\"planName\":null,\"panTypeId\":null,\"brandId\":2192,\"planDesc\":\"你好\",\"isShare\":\"0\",\"planStartDay\":\"2014-10-28
//    // 12:15:49\",\"planEndDay\":\"2014-11-29
//    // 12:15:49\",\"planType\":1,\"planStatus\":1,\"planNum\":null,\"couponSentAmount\":0,\"forecastPersonAmount\":null,\"couponUsedAmount\":null,\"coupon\":{\"customerGroup\":{\"creatorId\":null,\"updaterId\":null,\"createTime\":null,\"updateTime\":null,\"isDelete\":null,\"updaterName\":null,\"creatorName\":null,\"id\":null,\"gender\":null,\"birthdayStart\":null,\"birthdayEnd\":null,\"ageStart\":null,\"ageEnd\":null,\"joinTimeType\":null,\"joinTimeStart\":null,\"joinTimeEnd\":null,\"joinTimeDynamic\":null,\"beMemberType\":null,\"beMemberStart\":null,\"beMemberEnd\":null,\"beMemberDynamic\":null,\"lastConsumeType\":null,\"lastConsumeStart\":null,\"lastConsumeEnd\":null,\"lastConsumeDynamic\":null,\"lastBookType\":null,\"lastBookStart\":null,\"lastBookEnd\":null,\"lastBookDynamic\":null,\"lastQueueType\":null,\"lastQueueStart\":null,\"lastQueueEnd\":null,\"lastQueueDynamic\":null,\"consumeCycleOperate\":null,\"consumeCycleValue\":null,\"consumeCycleUnit\":null,\"curConsumeType\":null,\"curConsumeOperate\":null,\"curConsumeValue\":null,\"averTconsumeType\":null,\"averTconsumeOperate\":null,\"averTconsumeValue\":null,\"averTconsumeScope\":null,\"averTconsumeStart\":null,\"averTconsumeEnd\":null,\"averPconsumeType\":null,\"averPconsumeOperate\":null,\"averPconsumeValue\":null,\"averPconsumeScope\":null,\"averPconsumeStart\":null,\"averPconsumeEnd\":null,\"allConsumeType\":null,\"allConsumeOperate\":null,\"allConsumeValue\":null,\"allConsumeScope\":null,\"allConsumeStart\":null,\"allConsumeEnd\":null,\"storedType\":null,\"storedOperate\":null,\"storedValue\":null,\"storedScope\":null,\"storedStart\":null,\"storedEnd\":null,\"creditsType\":null,\"creditsOperate\":null,\"creditsValue\":null,\"isBookingShop\":\"NO\",\"isFirstBooking\":null,\"bookingFrequency\":3},\"planPublish\":{\"creatorId\":null,\"updaterId\":null,\"createTime\":null,\"updateTime\":null,\"isDelete\":null,\"updaterName\":null,\"creatorName\":null,\"id\":null,\"isNotify\":null,\"title\":null,\"sysFileId\":32,\"content\":null,\"notifyWay\":1,\"commercialId\":\"800000001\",\"fileName\":null,\"fileUrl\":null,\"commercialName\":null},\"sendDayRuleList\":[{\"creatorId\":null,\"updaterId\":null,\"createTime\":null,\"updateTime\":null,\"isDelete\":null,\"updaterName\":null,\"creatorName\":null,\"id\":null,\"planId\":125,\"timeType\":\"FESTIVAL\",\"timeValue\":null}],\"dynamicConditionList\":[{\"creatorId\":null,\"updaterId\":null,\"createTime\":null,\"updateTime\":null,\"isDelete\":null,\"updaterName\":null,\"creatorName\":null,\"id\":1,\"planId\":125,\"conditionType\":null,\"conditionValue\":5}],\"customerConditionList\":null,\"couponRule\":{\"creatorId\":null,\"updaterId\":null,\"createTime\":null,\"updateTime\":null,\"isDelete\":null,\"updaterName\":null,\"creatorName\":null,\"id\":null,\"needCheck\":null,\"isCurDay\":null,\"redirectType\":\"COPY\",\"startTime\":\"2014-12-16
//    // 19:56:01\",\"endTime\":null,\"sendType\":null,\"beforeDayNum\":null,\"useWeek\":null,\"useFestival\":null,\"isHandSend\":null},\"marketAssCoupon\":{\"creatorId\":null,\"updaterId\":null,\"createTime\":null,\"updateTime\":\"2014-11-29
//    // 12:15:49\",\"isDelete\":null,\"updaterName\":null,\"creatorName\":null,\"id\":null,\"planId\":null,\"couponId\":568,\"coupon\":null,\"validType\":null,\"validStartDay\":null,\"validEndDay\":null,\"validDayNum\":null,\"sendCount\":null,\"eachUseNum\":null,\"eachSendNum\":null,\"prizeInfoId\":null}},\"lottery\":null}";
//    // SpecialMarketingVo destVo = (SpecialMarketingVo) json2Object(sourceStr,
//    // SpecialMarketingVo.class);
//    // System.out.println(destVo.getPlanStartDay());
//    //
//    //
//    // }
//}
